// 导出一个箭头函数，函数接收一个上下文参数
// validate_code 是否校验验证码
export default ctx => ({
	user_name: {
		rules: [
			{
				required: true,
				errorMessage: '请填写{label}',
			},
			{
				minLength: 1,
				maxLength: 10,
				errorMessage: '{label}长度在 {minLength}到{maxLength}个字符',
			}
		],
		label: '用户名',
	},
	account: {
		// name 字段的校验规则
		rules: [
			// 校验 name 不能为空
			{
				required: true,
				errorMessage: '请填写{label}',
			},
			// 对name字段进行长度验证
			{
				minLength: 5,
				maxLength: 16,
				errorMessage: '{label}长度在 {minLength}到{maxLength}个字符',
			}
		],
		// 当前表单域的字段中文名，可不填写
		label: '账号',
		// 校验触发时机，默认 submit
		// validateTrigger: 'bind'
	},
	password: {
		rules: [{
				required: true,
				errorMessage: '请填写{label}'
			},
			{
				minLength: 6,
				maxLength: 16,
				errorMessage: '{label}长度在{minLength}到{maxLength}之间'
			}
		],
		label: '密码',
	},
	phone: {
		rules: [{
				required: true,
				errorMessage: '请填写{label}'
			},
			{
				minLength: 11,
				errorMessage: '{label}长度不足'
			},
			{
				pattern: /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/,
				errorMessage: '{label}格式错误'
			}
		],
		label: '手机号',
	},
	captcha: {
		rules: [{
				required: true,
				errorMessage: '请填写{label}'
			},
			{
				minLength: 6,
				errorMessage: '{label}长度不足'
			},
			{ // 验证函数，成功了返回 true，失败了调用 callback 传入错误原因
				validateFunction(rule, value, data, callback) {
					if (value === ctx.real_code) return true;
					callback('验证码错误')
				}
			}
		],
		label: '验证码',
	}
})
